home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / pc_files / mktdata / econdata / docutils / pdgsup.exe / PRESS.DOC < prev    next >
Text File  |  1992-03-17  |  10KB  |  215 lines

  1.                    Data Bank Compression Programs
  2.  
  3.     There are two compression programs: CPRESS and HPRESS.  CPRESS is the 
  4. orginal PRESS program, while HPRESS compresses G workspace bank directly 
  5. into a hashed bank.  Hashed banks are now the standard data banks that 
  6. I.E.R.F. creates and maintains.  The compression routines for hashed and
  7. compressed banks are essentially the same, however, with the hashed banks
  8. we have added a far superior method of indexing the data series.
  9.  
  10.     Since the compression of both types of banks is so similar, the syntax 
  11. and usage for both compression programs are essentially the same as well.
  12. Therefore, what follows assumes one is using HPRESS.  If you wish to use 
  13. the original compression program, simply substitute CPRESS where HPRESS 
  14. appears and read 'compress,' where 'hash' appears below.
  15.  
  16.     The HPRESS data bank compression program can generally reduce the size
  17. of a G data bank by at least a factor of 2 and sometimes by much more.  
  18. The banks which it produces can be used directly in G and PDG 5.05 and above.  
  19.  
  20.     The general invocation of HPRESS is:
  21.  
  22.     hpress <original_bank> [hashed_bank] [-m<missing>] [-s<maxslash>]
  23.  
  24. As usual, the <> enclose required items; [ ], optional items.
  25. Here are several examples:
  26.  
  27.     hpress nipaq 
  28.     hpress nipaq e:nipaq
  29.     hpress nipaq -m-999999
  30.     hpress nipaq -s2
  31.     hpress nipaq e:nipaq -m-999999 -s4
  32.  
  33. If no hashed bank is named, as in the first example, the original bank 
  34. name, but with different extensions is used for the output bank.  If the data 
  35. source has used some unusual value, such as -999999, to indicate a missing  
  36. value, these observations may be turned to zeroes using the -m option, as in 
  37. the last example.  The meaning of the "maxslash" option is explained below.
  38.  
  39. Banks which have been pressed by HPRESS have the extensions ".hin" and ".hbk" 
  40. for their index and data files, respectively.  To assign a hashed bank 
  41. in G or PDG, the command is simply
  42.  
  43.     hbk <bank_name>
  44.  
  45. for example
  46.  
  47.     hbk nipaq
  48.  
  49. assigns the hashed quarterly NIPA bank.  All other commands should then 
  50. work exactly as with any other assigned bank.  It is NOT possible to assign a 
  51. hashed bank as a workspace with the wsb command.  It IS possible to assign 
  52. a hashed bank as the initial bank in the g.cfg file.
  53.  
  54. HPRESS does two things to compress each series.
  55. 1.   Leading and trailing zeroes are removed from the series.
  56. 2.   Whenever possible, a series is represented mainly by 2-byte
  57.      integers rather than by 4-byte floating point numbers.
  58.  
  59. To accomplish the second step, the number of decimal places in each series is
  60. found and the decimal point is slid to the right that many places and the
  61. result expressed as a 4-byte integer.  (If some number is too big to be 
  62. expressed as a 4-byte integer, the number of decimal places is reduced and the 
  63. process repeated.)  First differences of the (non-zero) values are then 
  64. calculated and checked for their expressability as two-byte integers.  If all 
  65. of them pass, the series is then stored by recording the starting date, 
  66. frequencey, number of observations, number of decimal places, starting 
  67. observation as a four-byte integer and then the first differences as two-byte 
  68. integers.  If this compression fails, then either (a) the numbers are stored as four-byte 
  69. floating-point numbers or (b) the differences are divided by a power of 2 up 
  70. to a maximum of "maxslash" as given by the -s option.
  71.  
  72. What precision is possible in a compressed series?  A laser printer typically 
  73. prints 300 dots per inch.  The precision of the first differences in a 
  74. compressed series is comparable to one such dot in a graph nine feet high!  
  75. Although all series in the US quarterly national accounts from 1947 to 1988 
  76. compress with complete accuracy, about five percent of the series in the Blue 
  77. Pages of the Survey of Current Business fail, and about ten percent of the 
  78. series in the International Financial Statistics fail to compress. This 
  79. failure occurs when series are being carried to six or seven significant 
  80. figures in the sources.  Obviously, this much accuracy is seldom of any value 
  81. in economic use of the series.  If compaction is quite important, you may 
  82. therefore want to compress these series at a minor cost in terms of accuracy.  
  83. To do so, use the -s option on the command line to set "maxslash", the maximum 
  84. power of 2 which will be used to divide the differences to get them down to 
  85. the size which can be expressed as a two-byte integer.  Obviously, the slash 
  86. value actually used for each series is stored with the series and is used by G 
  87. in interpreting the compressed series.  A file called "forced" is created with 
  88. each compression.  It lists all series either slashed (marked "forced") or 
  89. dumped as four-byte floating point numbers (marked "gave up").  This file has 
  90. the form of an add file for G to draw graphs of the original and compressed 
  91. series.  The default value of maxslash is 0; only compression with perfect 
  92. accuracy allowed.  However, values of maxslash as high as 4 have not led to 
  93. graphically distinguishable series.  (Files on ECONDATA, the replacement of 
  94. MECCA, are compressed with maxslash = 0.)
  95.  
  96. Even in the case of failure in compression, the elimination of leading and 
  97. trailing zeroes often reduces the size of the bank.  Also, the organization
  98. of index file in a hashed bank greatly speeds up the series searching process
  99. in PDG, among others.
  100.  
  101.     The easist way to update a hashed bank is by using HSPLICE.  There is 
  102. another (and, unfortunately, more tedious) way to update a hashed bank.  For 
  103. example, to update a hashed bank, say nipaq.hbk, from the file newnipq.hbk, 
  104. the steps are as follows:
  105.  
  106. 1.  Run the BUPS program (2.0) included in the PDG 5.1 package:
  107.        bups nipaq
  108.     This will create the ascii file nipaq.bup.
  109.  
  110. 2.    Start G or PDG and select option 'a' on the opening menu, and set the 
  111.     starting date and size of the updated bank. Then do:
  112.        hbk nipaq
  113.        add nipaq.bup
  114.        hbk newnipq 
  115.        add nipaq.bup
  116.        q
  117.  
  118. 3.  The workspace bank of G or PDG is now the updated bank. Rename it.  If it 
  119.     was named ws and we wanted to rename it upnipaq, then do
  120.        ren ws.* upnipaq.*
  121.  
  122. 4.  If you wish to compress it, do
  123.        hpress upnipaq
  124.  
  125. When you have checked that all is well in the updated bank, you may, of 
  126. course, wish to rename it to nipaq. 
  127.  
  128.  
  129.                     **********************************
  130.                     **     Note for Programers      **
  131.                     **********************************
  132.  
  133. The precise form of the hashed bank .hin and .hbk files is as follows:
  134.  
  135. The ".hin" file contains:
  136.    item                      size in bytes           C type
  137.    ==============================================================
  138.    ns                        4                       long
  139.    nbins                     2                       unsigned
  140.    nsb                       2*nbins                 unsigned
  141.    ncharb                    2*nbins                 unsigned
  142.    posbin                    4*nbins                 unsigned
  143.    binname(0)                nchar[0]                char
  144.    binposts(0)               4*nnmsb[0]              long
  145.    binname(1)                nchar[1]                char
  146.    binposts(1)               4*nnmsb[1]              long
  147.    binname(2)                nchar[2]                char
  148.    binposts(2)               4*nnmsb[2]              long
  149.    .
  150.    .
  151.    binname(nbins-1)          nchar[nbins-1]          char
  152.    binposts(nbins-1)         4*nnmsb[nbins-1]        long
  153.  
  154.    Here, ns denotes the number of series in the bank.  The series are 
  155.    separated into "bins".  The number of bins in the bank is denoted by 
  156.    nbins.  The number of series in each bin is denoted by the array nsb.  
  157.    The sum of the number of characters in the names (including each '\0') 
  158.    of the series contained in each bin is denoted by the array ncharb.  
  159.    The beginning positions in the ".hin" file of the first bytes of the 
  160.    binname() strings is given by the array posbin.  The string binname(i) 
  161.    denotes the concatination (including the \0's) of all the series names 
  162.    in the i-th bin.  Finally, binposts(i) denotes the array of beginning 
  163.    positions in the associated ".hbk" of the series in the the i-th bin.  
  164.    Of course, the ordering of the series in the binname() and binposts() 
  165.    arrays must be the same.
  166.  
  167.    Consider an example.  Suppose that the 3rd bin contains the series 
  168.    "joe", "dave", and "bill".  The string binname(3) would be
  169.  
  170.             "joe\0dave\0bill\0"  
  171.             
  172.    Suppose that the starting positions in the ".hbk" bank for the three  
  173.    series are 40700008, 490987, 3378294.  The array binposts(3) would then
  174.    be [40700008, 490987, 3378294].  And nsb[3] = 3, and ncharb[3] = 14.
  175.    If the beginning position of binname(3) in the ".hin" file is 4724, then
  176.    posbin[3] = 4724.
  177.  
  178.    To assign a bin number to a series you must use the following hashing
  179.    routine.  In C, the routine is:
  180.  
  181.    unsigned hash(char *s);
  182.  
  183.    hash(char *s)
  184.    {
  185.       unsigned bill;
  186.  
  187.       for (bill=0;*s!='\0';s++) bill = *s + 31*bill;
  188.       bill = bill%nbins;
  189.       return(bill);
  190.       }
  191.  
  192.    To continue with the example, to determine the bin which the series "joe"  
  193.    really belongs to you'd evaluate the  function hash("joe").
  194.  
  195. The .hbk file:
  196.     0 - 79           char       Name of bank (terminated with a null)
  197.     80 - 81          int        ns, number of series in the bank
  198.     82 - 85          long       psn, position in file of index
  199.     86 -                        first series, as described below
  200.     *(psn+1) -                  second series,
  201.     ...                         ...
  202.     psn              long       position in file of first byte of first series
  203.     psn+4            long       position in file of first byte of second series
  204.     ...                         ... on out to ns series
  205.  
  206. For each series, the format is:
  207.         byte    Content
  208.         0        base year
  209.         1        frequency*16+period
  210.         2        slash*16+maxplaces or 255 if not compressed
  211.         3-4        number of observations
  212.         5-8        first observation as a long
  213.         9 -        differences as integers
  214.         if not compressed, floats begin in byte 5    
  215.